<?php
/**
 * 后台操作日志控制器
 * @author yupoxiong<i@yupoxiong.com>
 */

declare (strict_types=1);

namespace app\admin\controller;

use support\Request;
use support\Response;
use app\admin\model\AdminLog;
use app\admin\model\AdminUser;
use think\db\exception\DbException;

class AdminLogController extends AdminBaseController
{
    /**
     * 列表
     * @param Request $request
     * @param AdminLog $model
     * @return Response
     * @throws DbException
     */
    public function index(Request $request, AdminLog $model): Response
    {
        $param = $request->all();
        $data  = $model->with('adminUser')->scope('where', $param)
            ->paginate([
                'list_rows' => $this->admin['admin_list_rows'],
                'var_page'  => 'page',
                'query'     => $request->get()
            ]);


        // 关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'            => $data,
            'page'            => $data->render(),
            'total'           => $data->total(),
            'admin_user_list' => (new AdminUser())->select(),
        ]);
        return $this->fetch();
    }

    /**
     * @param Request $request
     * @param AdminLog $model
     * @return Response
     */
    public function detail(Request $request, AdminLog $model): Response
    {
        $id   = $request->input('id');
        $data = $model->with('adminLogData')->findOrEmpty($id);

        $this->assign([
            'data' => $data,
        ]);

        return $this->fetch();
    }

    /**
     * 获取操作IP的位置
     * @return Response
     */
    public function position(): Response
    {
        return admin_error('敬请期待');

    }
}
